package part21;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author wcj
 * @Date 2021/6/7 16:17
 * @Version 1.0
 */
public class Part213 {

    public static void main(String[] args) {

        /**
         * 缓存线程池
         */
        ExecutorService executorService = Executors.newCachedThreadPool();
        for (int i = 0; i < 5; i++) {
            executorService.execute(new LiftOff());
        }
        executorService.shutdown();
        System.out.println("------------------------------");

        /**
         * newFixedThreadPool()：固定线程数量的线程池
         */
        ExecutorService executorService1 = Executors.newFixedThreadPool(5);
        for (int i = 0; i < 5; i++) {
            executorService1.execute(new LiftOff());
        }
        executorService1.shutdown();
        System.out.println("--------------------");

        /**
         * 只含有一个线程的线程池:序列化任务
         */
        ExecutorService executorService2 = Executors.newSingleThreadExecutor();
        for (int i = 0; i < 5; i++) {
            executorService2.execute(new LiftOff());
        }
        executorService2.shutdown();
    }
}
